<%@page import="org.jfree.data.general.DefaultPieDataset"%>
<%@page import="org.jfree.chart.JFreeChart"%>
<%@page import="org.jfree.chart.ChartFactory"%>
<%@page import="org.jfree.chart.ChartUtilities"%>
<%@page import="java.io.File"%>
<%@page import="java.io.IOException"%>
<%@page import="memory.JvmInformation"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.awt.Color"%>
<%@page import="java.awt.Image"%>
<html>
<head>
<script type="text/javascript" src="<%= getServletContext().getContextPath() %>/js/scripts.js"></script>
<script type="text/javascript" src="<%= getServletContext().getContextPath() %>/js/jquery-1.2.1.js"></script>
<link rel="stylesheet" type="text/css" href="<%= getServletContext().getContextPath() %>/css/style.css" >
<script>
  $(document).ready(function(){
        $("#title").slideDown("slow");
        $("#info").slideDown("slow");
    });
 </script>
</head>
<body>
<%
  JvmInformation jvmobj = (JvmInformation)request.getAttribute("jvmobj");
  long max = jvmobj.getUsedMaxHeapMemo();
  float used  = jvmobj.getUsedHeapMemo();
  float per = (used/max ) * 100;
  DecimalFormat df = new DecimalFormat("0.00");  
  DefaultPieDataset pds = new DefaultPieDataset(); 
  pds.setValue("used memory "+ df.format(per) + " %", jvmobj.getUsedHeapMemo());
  pds.setValue("free memory "+df.format(100-per)+" %", jvmobj.getUsedMaxHeapMemo());
  JFreeChart jfc = ChartFactory.createPieChart("", pds, false, true, true);
  jfc.setBackgroundPaint(new Color(204,204,204));
  
  try{
	 ChartUtilities.saveChartAsPNG(new File(request.getRealPath("") + "/tmp/chart.png" ), jfc, 400, 200);	
  }catch(IOException e){
	 e.printStackTrace();
  }
%>
<div id="title" class="title"> Memory use </div>
<div id="info" class="info">
<div class="mem" >
<table>
  <tr>
	<td><b> Used heap memory</b></td><td>:<%= jvmobj.getUsedHeapMemo()/1024%> kbytes</td>
 </tr>
 <tr>
	<td><b>Used max heap memory</b></td><td>:<%= jvmobj.getUsedMaxHeapMemo()/1024%> kbytes</td>
 </tr>
 <tr>
	<td><b>Used committed memory</b></td><td>:<%= jvmobj.getUsedCommitedMemo()/1024%> kbytes</td>
 </tr>
 </table>
 </div>
 <img src="<%= request.getContextPath() + "/tmp/chart.png" %>">
 
</div>
</body>
</html>